home *** CD-ROM | disk | FTP | other *** search
- /*
- udp test translated into rexx
- from Amiga Magazine 93 udp.c test by Rudi Chiarito
-
- usage: udp host port localPort
-
- i.e. :
- shell1 udp localhost 4000 4001
- shell2 udp localhost 4001 4000
-
- to stop push <ctrl-c> in the shells
-
- */
-
- parse arg host remotePort localPort .
-
- remote.ADDRFAMILY = "INET"
- remote.ADDRPORT = remotePort
-
- addr = inetaddr(host)
- if addr == -1 then do
- if ~gethostbyname("SERVER",host) then do
- say "Host" host "non trovato."
- exit
- end
- remote.ADDRFAMILY = server.HOSTADDRTYPE
- remote.ADDRADDR = server.HOSTADDRLIST.0
- end
- else remote.ADDRADDR = addr
-
- sock = socket("INET","DGRAM","IP")
- if sock < 0 then do
- say "Non posso aprire il socket:" Errno()
- exit
- end
-
- LOCAL.ADDRFAMILY = "INET"
- LOCAL.ADDRADDR = 0
- LOCAL.ADDRPORT = localPort
- res = bind(sock,"LOCAL")
- if res < 0 then do
- say "Non posso allocare la porta:" Errno()
- exit
- end
-
- say "Host:" host
-
- call IOCTLSOCKET(sock,"FIONBIO",1)
-
- data = "Ciao"
- down = 0
- do while 1
-
- n = sendto(sock,data,0,"REMOTE")
- if n < 0 then do
- say "Errore di sendto():" Errno()
- exit
- end
-
- call Delay(10)
-
- if down then call writech("STDOUT",".")
-
- n = recvfrom(sock,"BUFF",10,0,"REMOTE")
- if n==-1 then do
- err = Errno()
- if err==35 then do
- if ~down then do
- call writech("STDOUT","Non ricevo piĆ¹ dati .")
- down=1
- end
- end
- else do
- say "Errore di recvfrom():" err
- exit
- end
- end
- else do
- say "Byte letti:" n
- down=0
- end
-
- end
-